package com.tzxs.pay.main.broadcast_receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.uuzuche.lib_zxing.activity.CodeUtils;

/**
 * Author: BuIsh
 * Date: 2018/9/10
 * Functions: 接收前置摄像头扫码结果的广播
 */
public abstract class ScannedResultBroadcastReceiver extends BroadcastReceiver {
    protected abstract void handleScannedResult(Bundle bundle);

    @Override
    public void onReceive(Context context, Intent intent) {
        String scannedResult = intent.getStringExtra("result");
        Bundle bundle = new Bundle();
        if (scannedResult.equals("cancel")) {
            bundle.putInt(CodeUtils.RESULT_TYPE, CodeUtils.RESULT_FAILED);
        } else {
            bundle.putInt(CodeUtils.RESULT_TYPE, CodeUtils.RESULT_SUCCESS);
            bundle.putString(CodeUtils.RESULT_STRING, scannedResult);
        }
        handleScannedResult(bundle);
    }
}